Skip to content

🐛 fix(webhook): keep KollectScope checks when the profile is missing - #307

Merged
konih merged 1 commit into
mainfrom
fix/kollecttarget-scope-missing-profile
Aug 18, 2026
Merged

🐛 fix(webhook): keep KollectScope checks when the profile is missing#307
konih merged 1 commit into
mainfrom
fix/kollecttarget-scope-missing-profile

Conversation

@konih

@konih konih commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

The namespaced half of #304. Independent of it — different file, no overlap, mergeable in any order.

validateScope returned nil as soon as the referenced KollectProfile was absent, so a KollectTarget applied before its profile skipped the namespace allow/deny checks and the resourceRules GVK check entirely.

Severity is lower here than on the cluster kind, because scopeCheck.enforceTarget already re-checks GVKs and namespaces at reconcile — a target admitted this way degrades rather than collecting. What was wrong is that admission accepted a spec it can fully evaluate: deniedNamespaces, allowedNamespaces and spec.resourceRules[].gvk do not depend on the profile at all. Only the profile targetGVK does, and CollectRuleGVKs ignores it whenever resourceRules is non-empty.

The resolve is now a switch: found resolves the GVK, NotFound continues with profileResolved = false, any other error still fails closed. GVK validation is skipped only where it would otherwise compare a zero GVK against a non-empty allowedGVKs and reject a legal create-before-profile.

Test first — TestKollectTargetValidator_scopeAdmissionMissingProfile covers denied namespace, out-of-allowlist namespace, and out-of-scope resourceRules GVK with no profile object present, plus the in-scope case that must stay admissible. Red before the change on the denied-namespace assertion.

Gates: task lint (golangci v2 + arch-lint) clean, task verify ok, task scrub ok, webhook unit tests green. envtest suites are CI-only on this host and fail identically on unmodified main here.

`validateScope` returned nil as soon as the referenced KollectProfile was
absent, so a KollectTarget applied before its profile skipped the namespace
allow/deny checks and the resourceRules GVK check entirely. PR #304 fixes the
same skip on the cluster-scoped kind; this is the namespaced half.

Severity is lower here than on the cluster kind: `scopeCheck.enforceTarget`
already re-checks GVKs and namespaces at reconcile, so a target admitted this
way degrades instead of collecting. What was wrong is that admission accepted a
spec it can fully evaluate — `deniedNamespaces`, `allowedNamespaces` and
`spec.resourceRules[].gvk` do not depend on the profile at all. Only the profile
`targetGVK` does, and `CollectRuleGVKs` ignores it whenever resourceRules is
non-empty.

The resolve now runs as a switch: found resolves the GVK, NotFound continues
with `profileResolved = false`, any other error still fails closed. GVK
validation is skipped only in the one case where it would compare against a zero
GVK — profile missing *and* no resourceRules — which would otherwise reject a
legal create-before-profile against a non-empty allowedGVKs.

Test first: `TestKollectTargetValidator_scopeAdmissionMissingProfile` covers
denied namespace, out-of-allowlist namespace, and out-of-scope resourceRules GVK
with no profile object present, plus the in-scope case that must stay
admissible. Red before the change on the denied-namespace assertion.

Gates: lint (golangci v2 + arch-lint) clean, verify ok, scrub ok, webhook unit
tests green. envtest suites (TestWebhookEnvtest, TestSetupWithManager_*) do not
run on this host — bin/k8s ships linux-amd64 assets only and setup-envtest is
rate-limited — so they are CI-only, and they fail identically on an unmodified
main checkout here.
@konih
konih force-pushed the fix/kollecttarget-scope-missing-profile branch from 52ad572 to fcf3f54 Compare August 18, 2026 09:42
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/webhook/v1alpha1/kollecttarget_webhook.go 90.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@konih
konih merged commit d233432 into main Aug 18, 2026
35 checks passed
@konih
konih deleted the fix/kollecttarget-scope-missing-profile branch August 18, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant